package service4user

import (
	"Gin-Gorm-boke/boke_common/define"
	models2 "Gin-Gorm-boke/boke_common/models"
	"Gin-Gorm-boke/boke_common/response"
	"github.com/gin-gonic/gin"
	"github.com/samber/lo"
)

func GetCategoryList(c *gin.Context) {
	var categoryList []models2.Category
	var ArticelList []models2.Article
	models2.Db.Model(new(models2.Article)).
		Where("status=?", define.ARTICLE_STATUS_NORMAL).
		Find(&ArticelList)

	idList := lo.Map(ArticelList, func(item models2.Article, _ int) int {
		return item.CategoryId
	})

	uniqIdList := lo.Uniq(idList)
	models2.Db.Model(new(models2.Category)).
		Where("id in ?", uniqIdList).
		Find(&categoryList)
	response.ResponseOK(c, categoryList)
	return
}
